home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / packer / tar / src / tar.h < prev    next >
C/C++ Source or Header  |  1995-03-09  |  6KB  |  193 lines

  1. /*
  2.  * Header file for public domain tar (tape archive) program.
  3.  *
  4.  * @(#)tar.h 1.24 87/11/06    Public Domain.
  5.  *
  6.  * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
  7.  */
  8.  
  9. /*
  10.  * Kludge for handling systems that can't cope with multiple
  11.  * external definitions of a variable.  In ONE routine (tar.c),
  12.  * we #define TAR_EXTERN to null; here, we set it to "extern" if
  13.  * it is not already set.
  14.  */
  15. #ifndef TAR_EXTERN
  16. #define TAR_EXTERN extern
  17. #endif
  18.  
  19. /*
  20.  * Header block on tape.
  21.  *
  22.  * I'm going to use traditional DP naming conventions here.
  23.  * A "block" is a big chunk of stuff that we do I/O on.
  24.  * A "record" is a piece of info that we care about.
  25.  * Typically many "record"s fit into a "block".
  26.  */
  27. #define    RECORDSIZE    512
  28. #define    NAMSIZ    100
  29. #define    TUNMLEN    32
  30. #define    TGNMLEN    32
  31.  
  32. union record {
  33.     char        charptr[RECORDSIZE];
  34.     struct header {
  35.         char    name[NAMSIZ];
  36.         char    mode[8];
  37.         char    uid[8];
  38.         char    gid[8];
  39.         char    size[12];
  40.         char    mtime[12];
  41.         char    chksum[8];
  42.         char    linkflag;
  43.         char    linkname[NAMSIZ];
  44.         char    magic[8];
  45.         char    uname[TUNMLEN];
  46.         char    gname[TGNMLEN];
  47.         char    devmajor[8];
  48.         char    devminor[8];
  49. #ifdef AMIGA
  50.         char    magic_cookie[9];    /* "AmigaTar" */
  51.         char    amiga_modes[9];        /* Protection, hex ascii */
  52.         char    comment[80];        /* Comment */
  53.         char    ds_Days[9];        /* Date Stamp, hex ascii */
  54.         char    ds_Minute[9];        /* Date Stamp, hex ascii */
  55.         char    ds_Tick[9];        /* Date Stamp, hex ascii */
  56. #endif
  57.     } header;
  58. };
  59.  
  60. /* The checksum field is filled with this while the checksum is computed. */
  61. #define    CHKBLANKS    "        "    /* 8 blanks, no null */
  62.  
  63. /* The magic field is filled with this if uname and gname are valid. */
  64. #define    TMAGIC        "ustar  "    /* 7 chars and a null */
  65.  
  66. /* The linkflag defines the type of file */
  67. #define    LF_OLDNORMAL    '\0'        /* Normal disk file, Unix compat */
  68. #define    LF_NORMAL    '0'        /* Normal disk file */
  69. #define    LF_LINK        '1'        /* Link to previously dumped file */
  70. #define    LF_SYMLINK    '2'        /* Symbolic link */
  71. #define    LF_CHR        '3'        /* Character special file */
  72. #define    LF_BLK        '4'        /* Block special file */
  73. #define    LF_DIR        '5'        /* Directory */
  74. #define    LF_FIFO        '6'        /* FIFO special file */
  75. #define    LF_CONTIG    '7'        /* Contiguous file */
  76. /* Further link types may be defined later. */
  77.  
  78. /*
  79.  * Exit codes from the "tar" program
  80.  */
  81. #define    EX_SUCCESS    0        /* success! */
  82. #define    EX_ARGSBAD    1        /* invalid args */
  83. #define    EX_BADFILE    2        /* invalid filename */
  84. #define    EX_BADARCH    3        /* bad archive */
  85. #define    EX_SYSTEM    4        /* system gave unexpected error */
  86.  
  87.  
  88. /*
  89.  * Global variables
  90.  */
  91. TAR_EXTERN union record    *ar_block;    /* Start of block of archive */
  92. TAR_EXTERN union record    *ar_record;    /* Current record of archive */
  93. TAR_EXTERN union record    *ar_last;    /* Last+1 record of archive block */
  94. TAR_EXTERN char        ar_reading;    /* 0 writing, !0 reading archive */
  95. TAR_EXTERN int        blocking;    /* Size of each block, in records */
  96. TAR_EXTERN int        blocksize;    /* Size of each block, in bytes */
  97. TAR_EXTERN char        *ar_file;    /* File containing archive */
  98. TAR_EXTERN char        *name_file;    /* File containing names to work on */
  99. TAR_EXTERN char        *tar;        /* Name of this program */
  100.  
  101. /*
  102.  * Flags from the command line
  103.  */
  104. #ifdef AMIGA
  105. TAR_EXTERN char f_archive_set;        /* -a */
  106. TAR_EXTERN char f_archive_check;    /* -A */
  107. #endif
  108. TAR_EXTERN char    f_reblock;        /* -B */
  109. TAR_EXTERN char    f_create;        /* -c */
  110. TAR_EXTERN char    f_diff;            /* -d */
  111. TAR_EXTERN char    f_dironly;        /* -D */
  112. TAR_EXTERN char    f_follow_links;        /* -h */
  113. TAR_EXTERN char    f_ignorez;        /* -i */
  114. TAR_EXTERN char    f_keep;            /* -k */
  115. TAR_EXTERN char f_local_filesys;    /* -l */
  116. TAR_EXTERN char    f_modified;        /* -m */
  117. TAR_EXTERN char    f_oldarch;        /* -o */
  118. TAR_EXTERN char    f_use_protection;    /* -p */
  119. TAR_EXTERN char    f_sayblock;        /* -R */
  120. TAR_EXTERN char    f_sorted_names;        /* -s */
  121. TAR_EXTERN char    f_list;            /* -t */
  122. TAR_EXTERN char    f_namefile;        /* -T */
  123. TAR_EXTERN char    f_verbose;        /* -v */
  124. TAR_EXTERN char    f_extract;        /* -x */
  125. TAR_EXTERN char    f_compress;        /* -z */
  126.  
  127. /*
  128.  * We now default to Unix Standard format rather than 4.2BSD tar format.
  129.  * The code can actually produce all three:
  130.  *    f_standard    ANSI standard
  131.  *    f_oldarch    V7
  132.  *    neither        4.2BSD
  133.  * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
  134.  * The only advantage to the "neither" option is that we can cmp(1) our
  135.  * output to the output of 4.2BSD tar, for debugging.
  136.  */
  137. #define        f_standard        (!f_oldarch)
  138.  
  139. /*
  140.  * Structure for keeping track of filenames and lists thereof.
  141.  */
  142. struct name {
  143.     struct name    *next;
  144.     short        length;        /* cached strlen(name) */
  145.     char        found;        /* A matching file has been found */
  146.     char        firstch;    /* First char is literally matched */
  147.     char        regexp;        /* This name is a regexp, not literal */
  148.     char        name[NAMSIZ+1];
  149. };
  150.  
  151. TAR_EXTERN struct name    *namelist;    /* Points to first name in list */
  152. TAR_EXTERN struct name    *namelast;    /* Points to last name in list */
  153.  
  154. TAR_EXTERN int        archive;    /* File descriptor for archive file */
  155. TAR_EXTERN int        errors;        /* # of files in error */
  156.  
  157. /*
  158.  *
  159.  * Due to the next struct declaration, each routine that includes
  160.  * "tar.h" must also include <sys/types.h>.  I tried to make it automatic,
  161.  * but System V has no defines in <sys/types.h>, so there is no way of
  162.  * knowing when it has been included.  In addition, it cannot be included
  163.  * twice, but must be included exactly once.  Argghh!
  164.  *
  165.  * Thanks, typedef.  Thanks, USG.
  166.  */
  167. struct link {
  168.     struct link    *next;
  169.     dev_t        dev;
  170.     ino_t        ino;
  171.     short        linkcount;
  172.     char        name[NAMSIZ+1];
  173. };
  174.  
  175. TAR_EXTERN struct link    *linklist;    /* Points to first link in list */
  176.  
  177.  
  178. /*
  179.  * Error recovery stuff
  180.  */
  181. TAR_EXTERN char        read_error_flag;
  182.  
  183.  
  184. /*
  185.  * Declarations of functions available to the world.
  186.  */
  187. union record *findrec();
  188. void userec();
  189. union record *endofrecs();
  190. void anno();
  191. #define     annorec(stream, msg)    anno(stream, msg, 0)    /* Cur rec */
  192. #define    annofile(stream, msg)    anno(stream, msg, 1)    /* Saved rec */
  193.